package com.cruzr.opengles.map.layer;

import android.opengl.GLES20;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

public class PointLayer {

    private static final String TAG = "PointLayer";

    private static final float POINT_Z = 0.3f;

    private FloatBuffer mPointBuffer;

    private float[] mPoint = {
            0, 0, POINT_Z
    };

    public PointLayer() {
        ByteBuffer pointBuffer = ByteBuffer.allocateDirect(mPoint.length * 4);// 1 float = 4 byte
        pointBuffer.order(ByteOrder.nativeOrder());
        mPointBuffer = pointBuffer.asFloatBuffer();
        mPointBuffer.put(mPoint);
        mPointBuffer.position(0);
    }

    public void updatePoint(float x, float y) {
        mPoint[0] = x;
        mPoint[1] = y;
        mPoint[2] = POINT_Z;

        mPointBuffer.put(mPoint);
        mPointBuffer.position(0);
    }

    public void drawMap(int positionHandle, int sizeHandler, float scale) {
        GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 0, mPointBuffer);
        GLES20.glUniform1f(sizeHandler, 0.1f * scale * 1080);

        GLES20.glEnableVertexAttribArray(positionHandle);
        GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
        GLES20.glDisableVertexAttribArray(positionHandle);
    }

}
